﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication4.Models;
using Syncfusion.DocIO.DLS;
using Syncfusion.Mvc.Grid;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;

namespace MvcApplication4.Controllers
{
    public class CadastroUBSController : Controller
    {
        private BD_Vacinas2Context db = new BD_Vacinas2Context();

        //
        // GET: /CadastroUBS/

        public ActionResult Index()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(100).ToList();
            return View(data);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(PagingParams args)
        {
            IEnumerable data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(100).ToList();
            return data.GridActions<tb_UBS>();
        }

        public ActionResult ExportToExcel()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(200).ToList();
            return data.GridExportToExcel<tb_UBS>("GridExcel.xlsx", ExcelVersion.Excel2010);
        }

        public ActionResult ExportToWord(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(200).ToList();
            return data.GridExportToWord<tb_UBS>("GridWord.doc", DocumentVersion.Word2007, args.ExportOption);
        }

        public ActionResult ExportToPDF(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(200).ToList();
            return data.GridExportToPDF<tb_UBS>("GridPDF.pdf", PdfVersion.Version1_7, args.ExportOption);
        }

        //
        // GET: /CadastroUBS/Details/5

        public ActionResult Details(int id = 0)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            if (tb_ubs == null)
            {
                return HttpNotFound();
            }
            return View(tb_ubs);
        }

        //
        // GET: /CadastroUBS/Create

        public ActionResult Create()
        {
            List<SelectListItem> estado = new List<SelectListItem>();
            estado.Add(new SelectListItem { Text = "AC", Selected = true });
            estado.Add(new SelectListItem { Text = "AL" });
            estado.Add(new SelectListItem { Text = "AP" });
            estado.Add(new SelectListItem { Text = "AM" });
            estado.Add(new SelectListItem { Text = "BA" });
            estado.Add(new SelectListItem { Text = "CE" });
            estado.Add(new SelectListItem { Text = "DF" });
            estado.Add(new SelectListItem { Text = "ES" });
            estado.Add(new SelectListItem { Text = "GO" });
            estado.Add(new SelectListItem { Text = "MA" });
            estado.Add(new SelectListItem { Text = "MT" });
            estado.Add(new SelectListItem { Text = "MS" });
            estado.Add(new SelectListItem { Text = "MG" });
            estado.Add(new SelectListItem { Text = "PA" });
            estado.Add(new SelectListItem { Text = "PB" });
            estado.Add(new SelectListItem { Text = "PR" });
            estado.Add(new SelectListItem { Text = "PE" });
            estado.Add(new SelectListItem { Text = "PI" });
            estado.Add(new SelectListItem { Text = "RJ" });
            estado.Add(new SelectListItem { Text = "RN" });
            estado.Add(new SelectListItem { Text = "RS" });
            estado.Add(new SelectListItem { Text = "RO" });
            estado.Add(new SelectListItem { Text = "RR" });
            estado.Add(new SelectListItem { Text = "SC" });
            estado.Add(new SelectListItem { Text = "SP" });
            estado.Add(new SelectListItem { Text = "SE" });
            estado.Add(new SelectListItem { Text = "TO" });
            ViewBag.Estado = estado;
            return View();
        }

        //
        // POST: /CadastroUBS/Create

        [HttpPost]
        public ActionResult Create(tb_UBS tb_ubs)
        {
            if (ModelState.IsValid)
            {
                db.tb_UBS.Add(tb_ubs);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(tb_ubs);
        }

        //
        // GET: /CadastroUBS/Edit/5

        public ActionResult Edit(int id = 0)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            if (tb_ubs == null)
            {
                return HttpNotFound();
            }

            List<SelectListItem> estado = new List<SelectListItem>();
            estado.Add(new SelectListItem { Text = "AC", Selected = true });
            estado.Add(new SelectListItem { Text = "AL" });
            estado.Add(new SelectListItem { Text = "AP" });
            estado.Add(new SelectListItem { Text = "AM" });
            estado.Add(new SelectListItem { Text = "BA" });
            estado.Add(new SelectListItem { Text = "CE" });
            estado.Add(new SelectListItem { Text = "DF" });
            estado.Add(new SelectListItem { Text = "ES" });
            estado.Add(new SelectListItem { Text = "GO" });
            estado.Add(new SelectListItem { Text = "MA" });
            estado.Add(new SelectListItem { Text = "MT" });
            estado.Add(new SelectListItem { Text = "MS" });
            estado.Add(new SelectListItem { Text = "MG" });
            estado.Add(new SelectListItem { Text = "PA" });
            estado.Add(new SelectListItem { Text = "PB" });
            estado.Add(new SelectListItem { Text = "PR" });
            estado.Add(new SelectListItem { Text = "PE" });
            estado.Add(new SelectListItem { Text = "PI" });
            estado.Add(new SelectListItem { Text = "RJ" });
            estado.Add(new SelectListItem { Text = "RN" });
            estado.Add(new SelectListItem { Text = "RS" });
            estado.Add(new SelectListItem { Text = "RO" });
            estado.Add(new SelectListItem { Text = "RR" });
            estado.Add(new SelectListItem { Text = "SC" });
            estado.Add(new SelectListItem { Text = "SP" });
            estado.Add(new SelectListItem { Text = "SE" });
            estado.Add(new SelectListItem { Text = "TO" });
            ViewBag.Estado = estado;

            return View(tb_ubs);
        }

        //
        // POST: /CadastroUBS/Edit/5

        [HttpPost]
        public ActionResult Edit(tb_UBS tb_ubs)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tb_ubs).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tb_ubs);
        }

        //
        // GET: /CadastroUBS/Delete/5

        public ActionResult Delete(int id = 0)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            if (tb_ubs == null)
            {
                return HttpNotFound();
            }
            return View(tb_ubs);
        }

        //
        // POST: /CadastroUBS/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            db.tb_UBS.Remove(tb_ubs);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }

    public class CopyOfCadastroUBSController : Controller
    {
        private BD_Vacinas2Context db = new BD_Vacinas2Context();

        //
        // GET: /CadastroUBS/

        public ActionResult Index()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(100).ToList();
            return View(data);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(PagingParams args)
        {
            IEnumerable data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(100).ToList();
            return data.GridActions<tb_UBS>();
        }

        public ActionResult ExportToExcel()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(200).ToList();
            return data.GridExportToExcel<tb_UBS>("GridExcel.xlsx", ExcelVersion.Excel2010);
        }

        public ActionResult ExportToWord(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(200).ToList();
            return data.GridExportToWord<tb_UBS>("GridWord.doc", DocumentVersion.Word2007, args.ExportOption);
        }

        public ActionResult ExportToPDF(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().tb_UBS.Take(200).ToList();
            return data.GridExportToPDF<tb_UBS>("GridPDF.pdf", PdfVersion.Version1_7, args.ExportOption);
        }

        //
        // GET: /CadastroUBS/Details/5

        public ActionResult Details(int id = 0)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            if (tb_ubs == null)
            {
                return HttpNotFound();
            }
            return View(tb_ubs);
        }

        //
        // GET: /CadastroUBS/Create

        public ActionResult Create()
        {
            List<SelectListItem> estado = new List<SelectListItem>();
            estado.Add(new SelectListItem { Text = "AC", Selected = true });
            estado.Add(new SelectListItem { Text = "AL" });
            estado.Add(new SelectListItem { Text = "AP" });
            estado.Add(new SelectListItem { Text = "AM" });
            estado.Add(new SelectListItem { Text = "BA" });
            estado.Add(new SelectListItem { Text = "CE" });
            estado.Add(new SelectListItem { Text = "DF" });
            estado.Add(new SelectListItem { Text = "ES" });
            estado.Add(new SelectListItem { Text = "GO" });
            estado.Add(new SelectListItem { Text = "MA" });
            estado.Add(new SelectListItem { Text = "MT" });
            estado.Add(new SelectListItem { Text = "MS" });
            estado.Add(new SelectListItem { Text = "MG" });
            estado.Add(new SelectListItem { Text = "PA" });
            estado.Add(new SelectListItem { Text = "PB" });
            estado.Add(new SelectListItem { Text = "PR" });
            estado.Add(new SelectListItem { Text = "PE" });
            estado.Add(new SelectListItem { Text = "PI" });
            estado.Add(new SelectListItem { Text = "RJ" });
            estado.Add(new SelectListItem { Text = "RN" });
            estado.Add(new SelectListItem { Text = "RS" });
            estado.Add(new SelectListItem { Text = "RO" });
            estado.Add(new SelectListItem { Text = "RR" });
            estado.Add(new SelectListItem { Text = "SC" });
            estado.Add(new SelectListItem { Text = "SP" });
            estado.Add(new SelectListItem { Text = "SE" });
            estado.Add(new SelectListItem { Text = "TO" });
            ViewBag.Estado = estado;
            return View();
        }

        //
        // POST: /CadastroUBS/Create

        [HttpPost]
        public ActionResult Create(tb_UBS tb_ubs)
        {
            if (ModelState.IsValid)
            {
                db.tb_UBS.Add(tb_ubs);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(tb_ubs);
        }

        //
        // GET: /CadastroUBS/Edit/5

        public ActionResult Edit(int id = 0)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            if (tb_ubs == null)
            {
                return HttpNotFound();
            }

            List<SelectListItem> estado = new List<SelectListItem>();
            estado.Add(new SelectListItem { Text = "AC", Selected = true });
            estado.Add(new SelectListItem { Text = "AL" });
            estado.Add(new SelectListItem { Text = "AP" });
            estado.Add(new SelectListItem { Text = "AM" });
            estado.Add(new SelectListItem { Text = "BA" });
            estado.Add(new SelectListItem { Text = "CE" });
            estado.Add(new SelectListItem { Text = "DF" });
            estado.Add(new SelectListItem { Text = "ES" });
            estado.Add(new SelectListItem { Text = "GO" });
            estado.Add(new SelectListItem { Text = "MA" });
            estado.Add(new SelectListItem { Text = "MT" });
            estado.Add(new SelectListItem { Text = "MS" });
            estado.Add(new SelectListItem { Text = "MG" });
            estado.Add(new SelectListItem { Text = "PA" });
            estado.Add(new SelectListItem { Text = "PB" });
            estado.Add(new SelectListItem { Text = "PR" });
            estado.Add(new SelectListItem { Text = "PE" });
            estado.Add(new SelectListItem { Text = "PI" });
            estado.Add(new SelectListItem { Text = "RJ" });
            estado.Add(new SelectListItem { Text = "RN" });
            estado.Add(new SelectListItem { Text = "RS" });
            estado.Add(new SelectListItem { Text = "RO" });
            estado.Add(new SelectListItem { Text = "RR" });
            estado.Add(new SelectListItem { Text = "SC" });
            estado.Add(new SelectListItem { Text = "SP" });
            estado.Add(new SelectListItem { Text = "SE" });
            estado.Add(new SelectListItem { Text = "TO" });
            ViewBag.Estado = estado;

            return View(tb_ubs);
        }

        //
        // POST: /CadastroUBS/Edit/5

        [HttpPost]
        public ActionResult Edit(tb_UBS tb_ubs)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tb_ubs).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tb_ubs);
        }

        //
        // GET: /CadastroUBS/Delete/5

        public ActionResult Delete(int id = 0)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            if (tb_ubs == null)
            {
                return HttpNotFound();
            }
            return View(tb_ubs);
        }

        //
        // POST: /CadastroUBS/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            tb_UBS tb_ubs = db.tb_UBS.Find(id);
            db.tb_UBS.Remove(tb_ubs);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}